<?php

class Solution
{
    public $queueHead = null;
    public $queueTail = null;

    /**
     * @param ListNode $head
     * @param Integer $val
     * @return ListNode
     */
    function removeElements($head, $val)
    {
        for ($node = $head; $node != null; $node = $node->next) {
            if ($node->val != $val) {
                $this->enqueue($node->val);
            }
        }

       echo $this->toString();
    }

    public function enqueue($e)
    {
        $node = new ListNode($e);
        $node->next = null;
        if ($this->queueTail == null) {
            $this->queueHead = $this->queueTail = $node;
        } else {
            $this->queueTail->next = $node;
            $this->queueTail = $node;
        }
    }

    public function toString()
    {
        $str = '';
        for ($node = $this->queueHead; $node != null; $node = $node->next) {
            $str .= $node->val . "->";
        }
        return $str . "null";
    }
}

class ListNode
{
    public $val = 0;
    public $next = null;

    function __construct($val)
    {
        $this->val = $val;
    }
}

$obj = new Solution();
$obj->enqueue("11");
$obj->enqueue("22");
$obj->enqueue("6");
$obj->enqueue("33");
$obj->enqueue("44");
$obj->enqueue("6");
$obj->enqueue("55");
$obj->enqueue("6");
$obj->enqueue("66");
$obj->enqueue("6");
$obj->enqueue("77");

$obj1 = new Solution();
$obj1->removeElements($obj->queueHead,6);
